#ifndef SES_DISPLAY_H_
#define SES_DISPLAY_H_

/**
* @file
* DRIVER FOR LCD Datavision DG-12232
*/

/*INCLUDES-------------------------------------------------------------------*/

#include <stdint.h>
#include <stdbool.h>

/*MACROS---------------------------------------------------------------------*/

// note that columns are split up to 2 controllers
#define DISPLAY_COLUMNS		  	122
#define DISPLAY_PAGES		  	4
#define DISPLAY_ROWS_PER_PAGE 	8
#define CONTROLLER_CNT 			2

#define LCD_CONTROL_PORT	PORTD
#define DISPLAY_DATA_PORT 	PORTE

#define DISPLAY_CS_PORT		PORTD
#define DISPLAY_CS_PIN		4

#define DISPLAY_A0_PORT		PORTD
#define DISPLAY_A0_PIN		6

#define DISPLAY_RD_PORT		PORTD
#define DISPLAY_RD_PIN		7

#define DISPLAY_WR_PORT		PORTD
#define DISPLAY_WR_PIN		5

// long define is looong... http://www.stupidvideo.net/funny-photo/?pid=58
#define DISPLAY_COMMAND_SET_DISPLAY_START_ADDR_TO_ZERO	0xC0


//
#define DISPLAY_COMMAND_ON		0xAF

//
#define DISPLAY_COMMAND_RESET	0xE2

// perform bitwise OR on column address and this value
#define DISPLAY_COMMAND_COLUMN	0x00

// perform bitwise OR on column page and this value
#define DISPLAY_COMMAND_PAGE	0xB8

// position of busy flag in status byte
#define DISPLAY_STATUS_BUSY		0x80



/*PROTOTYPES-----------------------------------------------------------------*/


/**
 * Initializes display
 * \li Inits Port
 * \li Resets Display
 * \li Activates Display
 * \li ...
 */
void display_init();


/**
 * Writes a byte to internal RAM of display.
 *
 * @param page		page address in RAM
 * @param column	column address in RAM
 * @param data		value to write
 *
 */
void display_write(uint8_t page, uint8_t column, uint8_t data);


/**
 * Writes complete page to display
 *
 * @param page		page address in RAM (0-3 first controller, 4-7 second one)
 * @param data		pagedata to write
 */
void display_write_page(uint8_t page, uint8_t *data);

/**
 * Clears the whole display.
 */
void display_clear();


#endif /* SES_DISPLAY_H_ */
